﻿@using Microsoft.AspNetCore.Mvc.Localization
@using Idsrv4.Admin.BusinessLogic.Shared.Dtos.Common
@using Idsrv4.Admin.UI.Configuration.Constants
@model Idsrv4.Admin.BusinessLogic.Identity.Dtos.Identity.Interfaces.IRoleClaimsDto
@inject IViewLocalizer Localizer

@{
    ViewBag.Title = Localizer["PageTitle"];
    Layout = "_Layout";
}


<form asp-area="@CommonConsts.AdminUIArea" id="role-claims-form" asp-controller="Identity" asp-action="RoleClaims" Method="post">
    <div class="row">

        <div class="col-12">
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item">
                        <a asp-area="@CommonConsts.AdminUIArea" asp-controller="Identity" asp-action="Roles">@Localizer["NavigationRoles"]</a>
                    </li>
                    <li class="breadcrumb-item">
                        <a asp-area="@CommonConsts.AdminUIArea" asp-controller="Identity" asp-action="Role" asp-route-id="@Model.RoleId">@Model.RoleName</a>
                    </li>
                    <li class="breadcrumb-item active" aria-current="page">@Localizer["PageTitle"]</li>
                </ol>
            </nav>
        </div>

        <div class="col-md-12">
            <h3>@Localizer["PageTitle"]</h3>

            <div asp-validation-summary="All" class="text-danger"></div>

            <!--Hidden -->
            <input type="hidden" asp-for="RoleId"/>
            <div class="card mt-3">
                <h5 class="card-header">@Localizer["PanelTitleNew"]</h5>
                <div class="card-body">

                    <!--Select with tags-->
                    <div class="form-group row">
                        <label asp-for="ClaimType" class="col-sm-3 col-form-label">
                            @await Html.PartialAsync("Role/Section/Label", "Type")
                        </label>
                        <div class="col-sm-9">
                            <picker id="ClaimType" multiple-select="false" min-search-text="2"
                                    selected-item="@Model.ClaimType" url="@Url.Action("SearchClaims", "Configuration")?claim"
                                    search-input-placeholder="@Localizer["PickerSearchItemPlaceholder"].Value"
                                    selected-items-title="@Localizer["PickerSelectedItemsTitle"].Value"
                                    search-result-title="@Localizer["PickerSearchResultTitle"].Value"
                                    suggested-items-title="@Localizer["PickerSuggestedItemsTitle"].Value"
                                    no-item-selected-title="@Localizer["PickerNoItemSelectedTitle"].Value"
                                    show-all-items-title="@Localizer["PickerShowAllItemsTitle"].Value"
                                    item-already-selected-title="@Localizer["PickerItemAlreadySelectedTitle"].Value"
                                    required="true" required-message="@Localizer["PickerRequiredMessage"].Value">
                            </picker>
                            <span asp-validation-for="ClaimType" class="text-danger"></span>
                        </div>
                    </div>

                    <!--Input - text -->
                    <div class="form-group row">
                        <label asp-for="ClaimValue" class="col-sm-3 col-form-label">
                            @await Html.PartialAsync("Role/Section/Label", "Value")
                        </label>
                        <div class="col-sm-9">
                            <input type="text" required class="form-control" asp-for="ClaimValue">
                            <span asp-validation-for="ClaimValue" class="text-danger"></span>
                        </div>
                    </div>

                    <!--Button-->
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">
                        </label>
                        <div class="col-sm-9">
                            <button type="submit" id="role-claims-button" class="btn btn-primary">@Localizer["ButtonAddClaim"]</button>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</form>

<div class="row">
    <div class="col-md-12">
        <div class="card mt-3">
            <h5 class="card-header">@Localizer["PanelTitle"]</h5>
            <div class="card-body">

                <div class="row table-responsive">
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>@Localizer["TableType"]</th>
                            <th>@Localizer["TableValue"]</th>
                            <th></th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach (var client in Model.Claims)
                        {
                            <tr>
                                <td>@client.ClaimType</td>
                                <td>@client.ClaimValue</td>
                                <td>
                                    <a asp-area="@CommonConsts.AdminUIArea" asp-action="RoleClaimsDelete" asp-route-claimId="@client.ClaimId" asp-route-id="@Model.RoleId" class="btn btn-danger">@Localizer["TableButtonRemove"]</a>
                                </td>
                            </tr>
                        }
                        </tbody>
                    </table>
                </div>

                <div class="row">
                    <div class="col-12">
                        @await Html.PartialAsync("Common/Pager", new Pager { Action = "RoleClaims", PageSize = Model.PageSize, TotalCount = Model.TotalCount })
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section scripts
{
    <script>
        $(function() {
            //Disable enter for this form
            FormMvc.disableEnter($('#role-claims-form'));

            //Allow validate hidden field
            FormMvc.allowValidateHiddenField($('#role-claims-form'));
        });
    </script>
}